<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="search()" ref="dataForm">
      <el-form-item label="类型">
        <el-select v-model="dataForm.actionType" placeholder="请选择">
          <el-option
            v-for="item in useroption"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.nickname" placeholder="昵称"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.phone" placeholder="手机号"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.operator" placeholder="操作人"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="search()">查询</el-button>
      </el-form-item>
    </el-form>
    <div class="integral">
      <div>总获得积分：{{ totalStatistic.totalGetPointNum }}分</div>
      <div>总扣除积分：{{ totalStatistic.totalUsePointNum }}分</div>
    </div>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      style="width: 100%;"
    >
      <el-table-column header-align="center" align="center" label="头像">
        <template slot-scope="scope">
          <img :src="scope.row.avatar" alt="">
        </template>
      </el-table-column>
      <el-table-column prop="nickname" header-align="center" align="center" label="昵称"></el-table-column>
      <el-table-column prop="phone" header-align="center" align="center" label="手机号"></el-table-column>
      <el-table-column header-align="center" align="center" label="类型">
        <template slot-scope="scope">
          {{ scope.row.actionType === 1 ? '运营加分' : '' }}
          {{ scope.row.actionType === 2 ? '运营减分' : '' }}
        </template>
      </el-table-column>
      <el-table-column header-align="center" align="center" label="分数">
        <template slot-scope="scope">
          {{ scope.row.actionType === 1 ? '+' : '-' }}{{ scope.row.pointNum }}
        </template>
      </el-table-column>
      <el-table-column prop="operator" header-align="center" align="center" label="操作人"></el-table-column>
      <el-table-column prop="gmtCreate" header-align="center" align="center" label="操作时间"></el-table-column>
      <el-table-column prop="actionReason" header-align="center" align="center" label="操作理由"></el-table-column>
      <el-table-column header-align="center" align="center" label="详情">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="lookOrCheck(scope.row.id)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>

    <!--查看s-->
    <el-dialog
      :close-on-click-modal="false"
      :visible.sync="listVisible"
      title="详情"
    >
      <div>
        <el-row :gutter="20" class="margin_10">
          <el-col :span="6" class="text_r">加分理由</el-col>
          <el-col :span="18">{{ actionDesc }}</el-col>
        </el-row>
        <el-row :gutter="20" class="margin_10">
          <el-col :span="6" class="text_r">加分描述</el-col>
          <el-col :span="18">{{ actionReason }}</el-col>
        </el-row>
        <el-row :gutter="20" class="margin_10">
          <el-col :span="6" class="text_r">图片说明：</el-col>
          <el-col :span="18">
            <div class="imgList">
              <div v-for="item in actionImages"><img :src="item" alt=""></div>
            </div>
          </el-col>
        </el-row>
      </div>
      <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="listVisible = false">返回</el-button>
        </span>
    </el-dialog>
    <!--兑换资源状态查看e-->
  </div>

</template>

<script>
  export default {
    data() {
      return {
        useroption: [
          {
            value: null,
            label: '全部'
          },
          {
            value: '1',
            label: '加分'
          },
          {
            value: '2',
            label: '减分'
          }
        ],
        actionDesc: '',
        actionReason: '',
        dataForm: {
          actionType: null
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        totalStatistic: {},
        listVisible: false,
        actionImages: []
      }
    },
    activated() {
      this.getDataList()
    },
    methods: {
      search() {
        this.pageIndex = 1
        this.getDataList()
      },
      // 获取数据列表
      getDataList() {
        this.dataListLoading = true
        this.dataForm.page = this.pageIndex
        this.dataForm.limit = this.pageSize
        this.$http({
          url: this.$http.adornUrl('/point/operateactionlog/list'),
          method: 'get',
          params: this.$http.adornParams(this.dataForm)
        }).then(({ data }) => {
          if (data && data.code === 0) {
            this.$refs['dataForm'].resetFields()
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
        // 获取统计数据
        this.$http({
          url: this.$http.adornUrl('/point/operateactionlog/getStatisticData'),
          method: 'get',
          params: this.$http.adornParams(this.dataForm)
        }).then(({ data }) => {
          if (data && data.code === 0) {
            this.totalStatistic = data.vo
          }
        })
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle(val) {
        this.pageIndex = val
        this.getDataList()
      },
      lookOrCheck(id) {
        this.listVisible = true
        this.$http({
          url: this.$http.adornUrl('/point/operateactionlog/getOperationDetail'),
          method: 'get',
          params: this.$http.adornParams({id: id})
        }).then(({ data }) => {
          console.log(data)
          if (data) {
            this.actionDesc = data.actionDesc
            this.actionReason = data.actionReason
            this.actionImages = data.actionImages ? JSON.parse(data.actionImages): []
          }
        })
      }
    }
  }
</script>
<style scoped>
  .integral{
    display: flex;
  }
  .integral>div{
    margin: 15px;
  }
  img{
    width: 50px;
    height: auto;
  }
  .imgList{
    display: flex;
    flex-wrap: wrap;
  }
  .imgList>div{
    width: 80px;
    margin: 5px 15px 5px 0;
  }
</style>
